package cn.stylefeng.guns.modular.system.workstation.controller;

import cn.stylefeng.guns.modular.deviceLedgerManagement.deviceLedger.entity.Equipment;
import cn.stylefeng.guns.modular.system.workstation.entity.Station;
import cn.stylefeng.guns.modular.system.workstation.pojo.request.StationRequest;
import cn.stylefeng.guns.modular.system.workstation.pojo.response.StationVo;
import cn.stylefeng.guns.modular.system.workstation.service.StationService;
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 工位信息表控制器
 *
 * @author PANL
 * @since 2023/12/05 14:22
 */
@RestController
@ApiResource(name = "工位信息表")
public class StationController {

    @Resource
    private StationService stationService;

    /**
     * 添加工位信息表
     *
     * @author PANL
     * @since 2023/12/05 14:22
     */
    @PostResource(name = "添加工位信息表", path = "/station/add")
    public ResponseData<Station> add(@RequestBody @Validated(StationRequest.add.class) StationRequest stationRequest) {
        Station one = stationService.getOne(new LambdaQueryWrapper<Station>().eq(Station::getStationCode, stationRequest.getStationCode()));
        if (one != null) {
            return new ErrorResponseData<Station>("500", "工位代码重复");
        }
        stationService.add(stationRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 删除工位信息表
     *
     * @author PANL
     * @since 2023/12/05 14:22
     */
    @PostResource(name = "删除工位信息表", path = "/station/delete")
    public ResponseData<?> delete(@RequestBody @Validated(StationRequest.delete.class) StationRequest stationRequest) {
        stationService.del(stationRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 批量删除工位信息表
     *
     * @author PANL
     * @since 2023/12/05 14:22
     */
    @PostResource(name = "批量删除工位信息表", path = "/station/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) StationRequest stationRequest) {
        stationService.batchDelete(stationRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑工位信息表
     *
     * @author PANL
     * @since 2023/12/05 14:22
     */
    @PostResource(name = "编辑工位信息表", path = "/station/edit")
    public ResponseData<?> edit(@RequestBody @Validated(StationRequest.edit.class) StationRequest stationRequest) {
        stationService.edit(stationRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看工位信息表详情
     *
     * @author PANL
     * @since 2023/12/05 14:22
     */
    @GetResource(name = "查看工位信息表详情", path = "/station/detail")
    public ResponseData<StationVo> detail(@Validated(StationRequest.detail.class) StationRequest stationRequest) {
        return new SuccessResponseData<>(stationService.detail(stationRequest));
    }

    /**
     * 获取工位信息表列表
     *
     * @author PANL
     * @since 2023/12/05 14:22
     */
    @GetResource(name = "获取工位信息表列表", path = "/station/list")
    public ResponseData<List<Station>> list(StationRequest stationRequest) {
        return new SuccessResponseData<>(stationService.findList(stationRequest));
    }

    /**
     * 获取工位信息表列表（带分页）
     *
     * @author PANL
     * @since 2023/12/05 14:22
     */
    @GetResource(name = "获取工位信息表列表（带分页）", path = "/station/page")
    public ResponseData<PageResult<Station>> page(StationRequest stationRequest) {
        return new SuccessResponseData<>(stationService.findPage(stationRequest));
    }

    @GetResource(name = "获取配置", path = "/station/config")
    public ResponseData<Map> config(String orgid) {
        return new SuccessResponseData<>(stationService.config(orgid));
    }

}
